package custom;

import java.util.Random;

public class CustomArray {
    public static int[] newRandom(int arrayLength, int lowerBound, int rangeLength) {
        int[] array = new int[arrayLength];
        Random random = new Random();
        for (int i = 0; i < array.length; i++)
            array[i] = random.nextInt(rangeLength) + lowerBound;
        return array;
    }

    public static int findIndexOfMax(int[] array) {
        int index = 0;
        for (int i = 1; i < array.length; i++)
            if (array[index] < array[i])
                index = i;
        return index;
    }

    public static void print(int[] array) {
        System.out.print("[");
        for (int i = 0; i < array.length; i++) {
            if (i != 0)
                System.out.print(",");
            System.out.print(" " + array[i]);
        }
        System.out.println(" ]");
    }

    public static int[] deleteByIndex(int[] array, int index) {
        int[] result = new int[array.length - 1];
        boolean flag = false;
        for (int i = 0; i < array.length; i++) {
            if (i == index) {
                flag = true;
                continue;
            }
            if (flag)
                result[i - 1] = array[i];
            else
                result[i] = array[i];
        }
        return result;
    }

    public static int[] addByIndex(int[] array, int number, int index) {
        int[] result = new int[array.length + 1];
        boolean flag = false;
        for (int i = 0; i < array.length; i++) {
            if (i == index) {
                result[i] = number;
                flag = true;
            }
            if (flag)
                result[i + 1] = array[i];
            else
                result[i] = array[i];
        }
        return result;
    }
}
